<template>
    <div class="app-container">
        <!--      <el-form v-show="submitStatus" class="formBox" :model="recordQueryParams" ref="recordQueryForm" size="small" :inline="true"  label-width="68px">-->
        <el-form class="formBox" :model="queryParams" ref="recordQueryForm" size="small" :inline="true" label-width="68px">

            <el-form-item label="顾客编号" prop="visitNum">
                <el-input v-model="queryParams.visitNum" :disabled="!submitStatus" placeholder="请输入顾客编号" clearable
                    style="width: 160px" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="姓名" prop="patientName" label-width="48px">
                <el-input v-model="queryParams.patientName" :disabled="!submitStatus" placeholder="请输入顾客姓名" clearable
                    style="width:140px" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="手机号" prop="patientPhone" label-width="60px">
                <el-input v-model="queryParams.patientPhone" :disabled="!submitStatus" placeholder="请输入手机号" clearable
                    style="width: 140px" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="身份证号" prop="idNum">
                <el-input v-model="queryParams.idNum" :disabled="!submitStatus" placeholder="请输入顾客身份证号" clearable
                    style="width: 170px" @keyup.enter.native="handleQuery" @focus="getSFZToSearch" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" :disabled="!submitStatus"
                    @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" :disabled="!submitStatus"
                    @click="rehandleQuery">重置</el-button>
            </el-form-item>

        </el-form>
        <el-form class="formBox formBox1" label-position="left" :model="patientItem" ref="patientItemForm" size="small"
            :inline="true" label-width="68px">
            <el-row>
                <el-form-item label="顾客编号" prop="visitNum">
                    <el-input v-model="patientItem.visitNum" placeholder="顾客编号" clearable style="width: 160px"
                        :disabled="true" />
                </el-form-item>
                <el-form-item label="姓名" prop="patientName">
                    <el-input v-model="patientItem.patientName" placeholder="顾客姓名" clearable style="width: 160px"
                        :disabled="true" />
                </el-form-item>
                <el-form-item label="性别" prop="sex">
                    <el-select :disabled="true" v-model="patientItem.sex" placeholder="性别" clearable style="width: 160px">
                        <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                            :value="dict.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="年龄" prop="age">
                    <el-input v-model="patientItem.age" placeholder="顾客年龄" clearable style="width: 160px"
                        :disabled="true" />
                </el-form-item>
                <el-form-item label="手机号" prop="patientPhone">
                    <el-input v-model="patientItem.patientPhone" placeholder="顾客手机号" clearable style="width: 160px"
                        :disabled="true" />
                </el-form-item>
            </el-row>
            <el-row>
                <el-form-item label="状态" prop="status">
                    <el-select v-model="patientItem.status" placeholder="诊断状态" clearable style="width: 160px"
                        :disabled="true">
                        <el-option v-for="dict in dict.type.sys_diagnosis_status" :key="dict.value" :label="dict.label"
                            :value="dict.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="诊断医生" prop="doctor">
                    <el-input v-model="patientItem.doctor" placeholder="诊断医生" clearable style="width: 160px"
                        :disabled="true" />
                </el-form-item>
                <el-form-item label="初诊日期" prop="doctorTime">
                    <el-input v-model="patientItem.doctorTime" placeholder="初诊日期" clearable style="width: 160px"
                        :disabled="true" />
                </el-form-item>
                <el-form-item label="咨询医生" prop="consultationer">
                    <el-input v-model="patientItem.consultationer" placeholder="咨询医生" clearable style="width: 160px"
                        :disabled="true" />
                </el-form-item>
                <el-form-item label="确费状态" prop="confirmExpense">
                    <el-input v-model="patientItemConfirmExpense" class="inputRed" placeholder="缴费状态" clearable
                        style="width: 160px;" :disabled="true" />
                </el-form-item>
            </el-row>
            <div>
                <el-form-item label="医生诊断" prop="doctorDiagnosis">
                    <el-input v-model="patientItem.doctorDiagnosis" type="textarea" :rows="3" placeholder="医生诊断" clearable
                        style="width: 400px" :disabled="true" />
                </el-form-item>
                <el-form-item label="医生方案" prop="doctorPlan">
                    <el-input v-model="patientItem.doctorPlan" type="textarea" :rows="3" placeholder="医生方案" clearable
                        style="width: 400px" :disabled="true" />
                </el-form-item>
            </div>
        </el-form>
        <div class="formBox treatmentParametersListBox"
            v-if="treatmentParametersList && treatmentParametersList.length > 0">
            <el-checkbox-group v-model="checkboxGroup1" @change="getTreatmentParametersItem" class="smallBox">
                <el-checkbox-button v-for="(item, index) in treatmentParametersList" :key="index" :label="item"
                    :disabled="item.spareNum === 0" border>
                    <span>{{ item.packageContent }}</span>
                    <span class="numBox"> {{ item.num }} </span>次,余
                    <span class="numBox">{{ item.spareNum }} </span>次<span v-html="getHtml(item.todayIsSign)"></span>
                </el-checkbox-button>
            </el-checkbox-group>
            <!-- <div class="smallBox" v-for="(item, index) in treatmentParametersList" :key="index">
                <el-button size="medium" :disabled="!submitStatus || item.spareNum == 0"
                    :type="index == btnIndex ? 'primary' : ''" @click="getTreatmentParametersItem(item, index)">

                    <span>{{ item.packageContent }}</span>
                    <span class="numBox"> {{ item.num }} </span>次,余
                    <span class="numBox">{{ item.spareNum }} </span>次
                </el-button>
            </div> -->
        </div>
        <div style="display:flex;justify-content:center;margin:0 auto;text-align:center"
            v-if="treatmentParametersList && treatmentParametersList.length > 0">
            <el-button type="primary" class="formBtn" @click="submitItem">确 费</el-button>
            <el-button type="primary" class="formBtn" v-show="isShowBtnSign" @click="submitAndSign">确费并签到</el-button>
            <!-- <el-button type="success" class="formBtn" :disabled="patientItem.confirmExpense == '1' ? false : true"
                @click="attendItem(1)">签 到</el-button> -->
            <el-button type="success" class="formBtn" v-show="isShowBtnSign" @click="attendItem(1)">签 到</el-button>

        </div>
        <el-dialog title="选择顾客" :visible.sync="patientVisible" width="80%" :close-on-click-modal="false" v-dialogDrag
            append-to-body>
            <div class="formBox">
                <el-table border v-loading="loading" style="width: 100%" :data="patientList">
                    <el-table-column label="序号" align="center" type="index" width="50">
                        <template slot-scope="scope">
                            <span>{{ getIndex(scope.$index) }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="顾客编号" align="center" prop="visitNum" width="160" />
                    <el-table-column sortable label="顾客姓名" align="center" prop="patientName" :show-overflow-tooltip="true"
                        width="100" />
                    <el-table-column sortable label="顾客手机号" align="center" prop="patientPhone" :show-overflow-tooltip="true"
                        width="120" />
                    <el-table-column sortable label="性别" align="center" prop="sex" width="80">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
                        </template>
                    </el-table-column>
                    <el-table-column sortable label="年龄" align="center" prop="birthDate" width="80" />
                    <el-table-column sortable label="就诊门诊" align="center" prop="deptName" :show-overflow-tooltip="true" />

                    <el-table-column sortable label="状态" align="center" prop="status" :show-overflow-tooltip="true"
                        width="120">
<!--                        <template slot-scope="scope">-->
<!--                            <dict-tag :options="dict.type.sys_diagnosis_status" :value="scope.row.status"-->
<!--                                style="color:red" />-->
<!--                        </template>-->
                      <template slot-scope="scope">
                        <el-tag v-if="scope.row.status=='0'" type="danger">
                          <dict-tag
                            :options="dict.type.sys_diagnosis_status"
                            :value="scope.row.status"
                          />
                        </el-tag>
                        <el-tag v-else-if="scope.row.status=='1'" type="warning">
                          <dict-tag
                            :options="dict.type.sys_diagnosis_status"
                            :value="scope.row.status"
                          />
                        </el-tag>
                        <el-tag v-else-if="scope.row.status=='3'" type="success">
                          <dict-tag
                            :options="dict.type.sys_diagnosis_status"
                            :value="scope.row.status"
                          />
                        </el-tag>
                        <el-tag v-else-if="scope.row.status=='4'" >
                          <dict-tag
                            :options="dict.type.sys_diagnosis_status"
                            :value="scope.row.status"
                          />
                        </el-tag>
                      </template>
                    </el-table-column>
                    <el-table-column sortable label="顾客性质" align="center" prop="properties" width="100">
                        <template slot-scope="scope">
                            <dict-tag :options="dict.type.sys_patient_properties" :value="scope.row.properties" />
                        </template>
                    </el-table-column>

                    <el-table-column sortable label="登记人" align="center" prop="nickName" width="100"
                        :show-overflow-tooltip="true" />
                    <el-table-column sortable label="登记日期" align="center" prop="createTime" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.createTime) }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width"
                        width="100">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-caret-right"
                                @click="confirmPatient(scope.row)">点击选择</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <pagination v-show="total > 0" :total="total" :pageSizes.sync="pageSizes" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getPatientList" />
            </div>
        </el-dialog>

        <el-dialog title="缴费确认" :visible.sync="confirmPayVisible" :width="device !== 'mobile' ? '650px' : '100%'"  class="nopaddingDailog" :class="device !== 'mobile' ? '' : 'active'" append-to-body :close-on-click-modal="false"
            :before-close="closeConfirmPay" v-dialogDrag>

            <div class="uploadBtnBox">
                <el-button type="primary" plain icon="el-icon-s-custom" size="mini"
                    @click="uploadImageConfirmPay">上传凭证</el-button>
                <!--        <el-button class="btn" type="primary" plain icon="el-icon-picture" size="mini" >拍摄凭证</el-button>-->
                <el-button class="btn" type="primary" plain icon="el-icon-picture" size="mini"
                    @click="openShooting('0')" v-if="device!== 'mobile'" >拍摄凭证</el-button>
            </div>

            <div class="uploadImageBox" v-loading="loading">
                <div v-for="(item, index) in confirmPayImageInfo" :key="index" class="draggable-item">
                    <div class="icon-close" v-if="!item.visitNum" @click="removeImgConfirmPay(item, index)">
                        <i class="el-icon-close" style="background-color: #fff;color:red;font-weight: bold"></i>
                    </div>
                    <el-image style="width: 200px; height: 130px" :src="item.url" fit="fill"
                        :preview-src-list="confirmPaySrcList">
                    </el-image>
                </div>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="handleCloseConfirmPay('0')">确认已缴费</el-button>

            </div>
        </el-dialog>



        <!-- 调取摄像头拍摄 -->
        <el-dialog title="拍照" :visible.sync="cameraShootingVisible" v-dialogDrag :width="device !== 'mobile' ? '650px' : '100%'"  class="nopaddingDailog" :class="device !== 'mobile' ? '' : 'active'"
                   append-to-body :close-on-click-modal="false">
            <shooting v-if="cameraShootingVisible" :cameraShootingVisible="cameraShootingVisible"
                @closeShooting="closeShooting"></shooting>
        </el-dialog>
    </div>
</template>

<script>
import { mapGetters } from "vuex";
import { startReadCard } from "@/utils/getIdCard"
import { getVisit } from "@/api/patientRegistration/registrationList";
import {
    fileOpen,
    directoryOpen,
    fileSave,
    supported,
} from 'browser-fs-access';
import shooting from "@/views/components/camera/shooting"
import {
    getListForTreatment,
    getTreatmentBy,
    consentUploads,
    consentList,
    findSysVisitPlans
} from "@/api/treatmentWorkstation/treatmentManagement";
import {
    addsign,

} from "@/api/comfirmAttend/comfirmAttend";
export default {
    name: "confirmAttend",
    components: {
        shooting
    },
    dicts: [
        "sys_diagnosis_status",
        "sys_user_sex",
        "sys_patient_properties",
    ],
    props: ['baseAdd', 'clickVisitNum'],
    data() {
        return {
            checkboxGroup1: [],
            btnIndex: 0,
            treatmentParametersItemparams: [],
            treatmentParametersList: [],
            baseUrl: process.env.VUE_APP_BASE_API,
            loading: false,
            patientVisible: false,
            total: 0,
            pageSizes: [5, 10, 15, 20],
            patientList: [],
            patientItem: {},
            recordPatientList: [],
            // 查询参数
            recordQueryParams: {
                pageNum: 1,
                pageSize: 5,
                visitNum: undefined,
                patientName: undefined,
                patientPhone: undefined,
                idNum: undefined,
            },
            // 新增信息-------
            submitStatus: true,
            recordVisible: false,
            recordPageSizes: [5, 10, 15, 20],
            queryParams: {
                pageNum: 1,
                pageSize: 5,
                visitNum: undefined,
                patientName: undefined,
                patientId: undefined,
                patientPhone: undefined,
                idNum: undefined,
            },
            confirmPayVisible: false,
            confirmKnowVisible: false,
            positionSchemeVisible: false,
            uploadPhotosVisible: false,
            confirmPayBlobs: [],//获取的本地缴费确认照片信息
            confirmPayImageInfo: [],//上传的缴费确认照片信息
            blobs: [],//获取的知情同意书照片信息
            imageInfo: [],//上传的本地知情同意书照片信息
            positionSchemeBlobs: [], //获取的本地部位示意照片信息
            positionSchemeImageInfo: [], //上传的部位示意照片信息
            uploadPhotosBlobs: [], //获取的本地上传治疗照片信息
            uploadPhotosImageInfo: [], //上传的上传治疗照片信息
            confirmKnowNum: 0,//知情同意书角标
            confirmPayNum: 0,//缴费确认角标
            cameraShootingVisible: false,


            submitAndSignStatus: false,//点击了确费并签到按钮
            isShowBtnSign: false,//签到按钮是否显示

        };
    },
    computed: {
        ...mapGetters(["device"]),
        patientItemConfirmExpense() {
            return this.patientItem.confirmExpense == '1' ? '已确费' : '未确费'
        },
        srcList() {
            return this.imageInfo.map(n => n.url) || []
        },
        confirmPaySrcList() {
            return this.confirmPayImageInfo.map(n => n.url) || []
        },
        positionSchemeSrcList() {
            return this.positionSchemeImageInfo.map(n => n.url) || []
        },
        uploadPhotosSrcList() {
            return this.uploadPhotosImageInfo.map(n => n.url) || []
        },
        defaultTime: function () {
            let date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let day = date.getDate();
            month = month > 9 ? month : "0" + month;
            day = day < 10 ? "0" + day : day;
            let today = year + "-" + month + "-" + day;
            return [today, today];
        },
    },

    created() {

    },
    mounted() {
        if (this.clickVisitNum) {
            this.queryParams.visitNum = this.clickVisitNum
            this.handleQuery()
        }
    },
    methods: {
        getHtml(todayIsSign) {
            return todayIsSign ? '<span style="color:red">(今日已签到)</span>'
                : '<span>(今日未签到)</span>'
        },
        // 真实序号计算（计算分页影响）
        getIndex(index) {
            return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
        },
        async getSFZToSearch() {
            const res = await startReadCard()
            if (res.result == 3) {
                this.$message.warning('请把身份证放到读卡器上')
                // this.$refs.saveTagInput.blur();
            } else if (res.result == 2) {
                // this.$message.warning('设备不存在')
            } else {
                this.queryParams.idNum = res.gmsfhm
            }

        },

        //确费并签到
        submitAndSign() {
            if (this.checkboxGroup1.length > 0) {
                this.submitAndSignStatus = true
                this.confirmPayVisible = true
                this.getConsentList(this.patientItem.visitNum, '0')
            } else {
                this.$message.warning('请点击要确费的治疗项目')
            }
        },
        submitItem() {//确费
            if (this.checkboxGroup1.length > 0) {
                this.submitAndSignStatus = false
                this.confirmPayVisible = true
                this.getConsentList(this.patientItem.visitNum, '0')
            } else {
                this.$message.warning('请点击要确费的治疗项目')
            }
        },
        attendItem(type) {//签到
            if (this.checkboxGroup1.length > 0) {
                if (!this.patientItem.visitNum) {
                    this.$modal.msgError("请填写顾客信息");
                    return false
                }
                if (this.treatmentParametersItemparams && this.treatmentParametersItemparams.length == 0) {
                    this.$modal.msgError("请选择治疗项目!");
                    return false
                }
                let data = this.treatmentParametersItemparams
                let params = []
                data.forEach(function (item, index) {
                    item.type = type
                    params.push(item)
                });
                params = data
                addsign(params).then((response) => {
                    if (response.code == 200) {
                        this.$emit("closerecordVisible")
                    }
                })
            } else {
                this.$message.warning('请点击要确费的治疗项目')
            }
        },
        //获取已上传的缴费凭证或知情同意书
        getConsentList(visitNum, type) {
            consentList(visitNum, type).then(
                (response) => {
                    if (response.code == 200) {
                        if (type == '0') {
                            this.confirmPayImageInfo = response.data
                            this.confirmPayImageInfo.forEach((item) => {
                                item.url = this.baseUrl + item.url
                            })

                        } else if (type == '1') {
                            this.imageInfo = response.data
                            this.imageInfo.forEach((item) => {
                                item.url = this.baseUrl + item.url
                            })
                        } else if (type == '2') {
                            this.positionSchemeImageInfo = response.data
                            this.positionSchemeImageInfo.forEach((item) => {
                                item.url = this.baseUrl + item.url
                            })
                        } else {
                            this.uploadPhotosImageInfo = response.data
                            this.uploadPhotosImageInfo.forEach((item) => {
                                item.url = this.baseUrl + item.url
                            })
                        }
                    } else {
                        this.$modal.msgError(response.msg);

                    }
                }
            )
        },
        //删除图片
        removeImgConfirmPay(img, index) {
            this.$confirm('此操作将删除该照片, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    this.confirmPayImageInfo = this.confirmPayImageInfo.filter(item => {
                        return item.url != img.url
                    })
                    this.confirmPayBlobs.splice(index, 1)
                    console.log('this.confirmPayBlobs', this.confirmPayBlobs)

                })
                .then(() => {
                    this.$modal.msgSuccess("删除成功");
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
        },
        //获取图片
        async uploadImageConfirmPay() {
            const confirmPayBlobs = await fileOpen({
                mimeTypes: ['image/*'],
                multiple: true,
            });
            this.confirmPayBlobs.push(...confirmPayBlobs)
            this.confirmPayImageInfo = []
            this.confirmPayBlobs.forEach((item, index) => {
                const reader = new FileReader();
                reader.readAsDataURL(item)
                reader.onload = () => {
                    this.confirmPayImageInfo.push({ url: reader.result })
                };
            })
            console.log('this.confirmPayImageInfo', this.confirmPayImageInfo)
        },
        //关闭缴费确认
        closeConfirmPay() {
            this.confirmPayVisible = false
            this.confirmPayBlobs = []//获取的本地缴费确认照片信息
            this.confirmPayImageInfo = []//上传的缴费确认照片信息
        },

        //确认缴费
        handleCloseConfirmPay(type) {
            if (!this.patientItem.visitNum) {
                this.$modal.msgError("请填写顾客信息");
                return false
            }
            if (this.confirmPayBlobs.length > 0) {
                this.loading = true
                // 创建FormData对象，通过该对象实现批量文件上传
                let fd = new FormData()
                // 因为要上传多个文件，所以需要遍历一下才行,不要直接使用我们的文件数组进行上传，你会发现传给后台的是两个Object
                this.confirmPayBlobs.forEach(function (file) {
                    // 遍历files数组，将file添加到FormData对象中
                    fd.append("files", file, file.name)
                    // console.log('fd.append',file,fd.getAll('files'))
                })
                let Mdata = {
                    type: type,
                    visitNum: this.patientItem.visitNum,
                    data: fd,
                }
                consentUploads(Mdata).then(
                    (response) => {
                        if (response.code == 200) {
                            this.loading = false
                            this.$modal.msgSuccess(response.msg);
                            this.confirmPayVisible = false
                            this.confirmPayBlobs = []//获取的本地缴费确认照片信息
                            this.confirmPayImageInfo = []//上传的缴费确认照片信息
                            this.patientItem.confirmExpense = '1'
                            this.getConsentNum(this.patientItem.visitNum, '0')
                            if (this.submitAndSignStatus) {
                                this.attendItem(0)
                            }
                        } else {
                            this.loading = false
                            // this.$modal.msgError(response.msg);
                        }
                    }
                )
            } else {
                let that = this
                this.$confirm('是否确费?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    that.loading = true
                    let Mdata1 = {
                        type: type,
                        visitNum: that.patientItem.visitNum,
                        data: '',
                    }
                    consentUploads(Mdata1).then(
                        (response) => {
                            if (response.code == 200) {
                                that.$modal.msgSuccess(response.msg);
                                that.loading = false
                                that.confirmPayVisible = false
                                that.patientItem.confirmExpense = '1'
                                if (this.submitAndSignStatus) {
                                    this.attendItem(0)
                                }
                            } else {
                                //this.$modal.msgError(response.msg);
                                that.loading = false
                            }
                        }
                    )
                }).catch(() => {

                });

            }

        },

        // 真实序号计算（计算分页影响）
        getRecordIndex(index) {
            return (this.recordQueryParams.pageNum - 1) * this.recordQueryParams.pageSize + index + 1;
        },
        // 查询顾客列表(治疗中或治疗结束)
        getRecordPatientList() {
            if (this.submitStatus) {
                getListForTreatment(this.recordQueryParams).then(
                    (response) => {
                        if (response.rows.length > 0) {
                            if (response.rows.length == 1) {
                                this.patientItem = response.rows[0];
                                this.patientItem.birthDate = parseInt((new Date() - new Date(this.parseTime(this.patientItem.birthDate))) / (1000 * 60 * 60 * 24 * 365))
                                this.uploadPatientId = response.rows[0].patientId
                                this.getSysVisitPlans(response.rows[0].visitNum)
                            } else {
                                this.loading = true
                                this.patientVisible = true
                                this.recordPatientList = response.rows;
                                this.recordPatientList.forEach(item => {
                                    item.birthDate = parseInt((new Date() - new Date(this.parseTime(item.birthDate))) / (1000 * 60 * 60 * 24 * 365))
                                    if (item.consultationDiagnosis.includes(';')) {
                                        let Mobject = ''
                                        item.consultationDiagnosis.split(';').forEach(it => {
                                            Mobject += it + '<br>'
                                        })
                                        item.consultationDiagnosisValue = Mobject
                                    } else {
                                        item.consultationDiagnosisValue = item.consultationDiagnosis
                                    }
                                    if (item.doctorDiagnosis.includes(';')) {
                                        let MobjectDoctor = ''
                                        item.doctorDiagnosis.split(';').forEach(it => {
                                            MobjectDoctor += it + '<br>'
                                        })
                                        item.doctorDiagnosisValue = MobjectDoctor
                                    } else {
                                        item.doctorDiagnosisValue = item.doctorDiagnosis
                                    }
                                });

                                this.searchTotal = response.total;
                                this.loading = false;
                            }


                        } else {
                            // this.$modal.msgWarning("没找到对应的顾客！");
                            this.$confirm('该顾客无治疗中的项目!', '提示', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            })
                                .then((content) => {
                                    this.rehandleQuery()
                                })
                                .catch((error) => {
                                    this.rehandleQuery()
                                })

                        }


                    }
                )
            } else {
                getTreatmentBy(this.recordQueryParams.visitNum).then(
                    (response) => {
                        if (response.code == 200) {
                            this.patientItem = response.data;
                            this.patientItem.birthDate = parseInt((new Date() - new Date(this.parseTime(this.patientItem.birthDate))) / (1000 * 60 * 60 * 24 * 365))
                            // console.log('this.patientItem++++', this.patientItem)
                            this.uploadPatientId = response.data.patientId


                        } else {
                            this.$modal.alertError(response.msg);

                        }


                    }
                )
            }

        },
        getSysVisitPlans(visitNum) {
            findSysVisitPlans(visitNum).then(
                (response) => {
                    if (response.code == 200) {
                        let data = response.data
                        this.treatmentParametersList = data
                        // this.getTreatmentParametersItem(response.data[this.btnIndex], this.btnIndex)
                        if (data[this.btnIndex].spareNum > 0) {
                            // this.checkboxGroup1 = [data[this.btnIndex]]
                            this.getTreatmentParametersItem()
                        }


                    } else {
                        this.$modal.msgError(response.msg);
                    }
                }
            )
        },
        getTreatmentParametersItem() {
            console.log(this.checkboxGroup1)
            let that = this
            let data = that.checkboxGroup1
            that.treatmentParametersItemparams = []
            data.forEach(function (item, index) {
                let paramspatient = {
                    diagnosis: that.patientItem.doctorDiagnosis,
                    diagnosisPlan: that.patientItem.doctorPlan,
                    diseaseId: '',
                    doctorId: that.patientItem.doctorId,
                    patientAge: that.patientItem.age,
                    patientId: that.patientItem.patientId,
                    patientName: that.patientItem.patientName,
                    patientSex: that.patientItem.sex,
                    signId: '',
                    visitNum: that.patientItem.visitNum,
                }
                paramspatient.spareNum = item.spareNum
                paramspatient.treatmentName = item.packageContent
                paramspatient.status = item.status
                paramspatient.visitPlanId = item.id
                that.treatmentParametersItemparams.push(paramspatient)

            });
            that.isShowBtnSign = !!data.find(item => item.todayIsSign == false)

        },
        //调取摄像头拍摄
        openShooting(type) {
            this.cameraShootingVisible = true
            this.cameraShootingType = type

        },
        //关闭摄像头拍摄
        closeShooting(imgSrc, imgFile) {
            this.cameraShootingVisible = false
            console.log('closeShooting', imgSrc, imgFile)
            if (this.cameraShootingType == '0') {
                this.confirmPayBlobs = []
                this.confirmPayImageInfo = []
                this.confirmPayBlobs.push(imgFile)
                this.confirmPayImageInfo.push({ url: imgSrc })
            } else if (this.cameraShootingType == '1') {
                this.blobs = []
                this.imageInfo = []
                this.blobs.push(imgFile)
                this.imageInfo.push({ url: imgSrc })
            } else if (this.cameraShootingType == '3') {
                this.uploadPhotosBlobs = []
                this.uploadPhotosImageInfo = []
                this.uploadPhotosBlobs.push(imgFile)
                this.uploadPhotosImageInfo.push({ url: imgSrc })
            }

        },
        /** 搜索按钮操作 */
        recordHandleQuery() {
            this.recordQueryParams.pageNum = 1;
            if (this.recordQueryParams.visitNum || this.recordQueryParams.patientName || this.recordQueryParams.patientPhone || this.recordQueryParams.idNum) {
                this.getRecordPatientList();
            }
        },

        rehandleQuery() {
            this.resetForm("recordQueryForm");
            this.resetForm("patientItemForm");
            this.recordQueryParams = {
                pageNum: 1,
                pageSize: 5,
                visitNum: undefined,
                patientName: undefined,
                patientPhone: undefined,
                idNum: undefined,
            }
            this.queryParams = {
                pageNum: 1,
                pageSize: 5,
                visitNum: undefined,
                patientName: undefined,
                patientId: undefined,
                patientPhone: undefined,
                idNum: undefined,
            },
                this.uploadPatientId = ''
            this.patientItem = {}
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            if (this.queryParams.visitNum || this.queryParams.patientName || this.queryParams.idNum || this.queryParams.patientPhone) {
                this.getPatientList();
            }
        },
        // 获取顾客登记列表
        getPatientList() {
            getVisit(this.queryParams).then(
                (response) => {
                    if (response.rows.length > 0) {
                        if (response.rows.length == 1) {
                            this.patientItem = response.rows[0];
                            this.recordQueryParams = {
                                visitNum: response.rows[0].visitNum,
                                patientName: response.rows[0].patientName,
                            }
                            this.patientItem.birthDate = parseInt((new Date() - new Date(this.parseTime(this.patientItem.birthDate))) / (1000 * 60 * 60 * 24 * 365))
                            //获取检测指标列表
                            this.recordHandleQuery()
                        } else {
                            this.patientVisible = true
                            this.patientList = response.rows;
                            this.patientList.forEach(item => {
                                item.birthDate = parseInt((new Date() - new Date(this.parseTime(item.birthDate))) / (1000 * 60 * 60 * 24 * 365))
                            })
                            this.total = response.total;

                        }

                    } else {
                        // this.$modal.msgWarning("没找到对应的顾客！");
                        this.$confirm('没找到对应的顾客！请您自己搜索选择顾客', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        })
                            .then((content) => {
                                console.log('content', content)
                            })
                            .catch((error) => {
                                console.log('error', error)
                            })

                    }


                }
            )
        },
        confirmPatient(row) {
            this.patientItem = row
            console.log('confirmPatient', row)
            this.patientVisible = false
            this.recordQueryParams = {

                visitNum: row.visitNum,
                patientName: row.patientName,

            }
            this.getSysVisitPlans(row.visitNum)
            this.recordHandleQuery()

        },

    },
};
</script>
<style scoped rel="stylesheet/scss"  lang="scss">
::v-deep .el-form-item.is-required:not(.is-no-asterisk)>.el-form-item__label:before,
.el-form-item.is-required:not(.is-no-asterisk) .el-form-item__label-wrap>.el-form-item__label:before {
    display: inline-block;
    content: '*';
    color: red;
    margin-left: 4px;
}

::v-deep .el-form-item.is-required:not(.is-no-asterisk)>.el-form-item__label::after,
.el-form-item.is-required:not(.is-no-asterisk) .el-form-item__label-wrap>.el-form-item__label::after {
    display: none;
}

::v-deep .el-input.is-disabled .el-input__inner {
    color: #606266;
}

::v-deep .el-checkbox-button {
    margin: 0px 10px;
    border: 1px solid #eee;
    border-radius: 4px;
}

::v-deep .el-checkbox-button__inner {
    border-radius: 4px !important;
}

.uploadBtnBox {
    display: flex;

    .btn {
        margin-left: 10px;
    }
}

.positionSchemeBox {
    display: flex;
    justify-content: space-between;
}

.uploadImageBox {
    //width: 500px;
    min-height: 500px;
    border: 1px solid #f3a4a1;
    margin: 10px auto;
}

.formBtn {
    margin: 0 20px;
    display: block;
}

.img-style {
    width: 500px;
    height: 500px;

    ::v-deep .el-image__error {
        opacity: 0;
    }
}

::v-deep .el-input.is-disabled .el-input__inner {
    color: #606266;
}

::v-deep .inputRed.el-input.is-disabled .el-input__inner {
    color: red;
}

::v-deep .el-textarea.is-disabled .el-textarea__inner {
    color: #606266;
}


.treatmentParametersListBox {
    display: flex;
    //flex-wrap: wrap;
    justify-content: center;

    .smallBox {
        margin-right: 10px;
        //margin-bottom: 10px;
        font-size: 18px;

        .numBox {
            font-weight: bold;
            color: red;
            font-size: 20px;
        }
    }


}

.treatmentParametersListBoxBtn {
    display: flex;
    align-items: center;

    //max-width: 990px;
    //border: 1px solid #C0C4CC;
    .el-form-item {
        margin-top: 10px;
    }

}

::v-deep .el-dialog {
    margin-top: 0 !important;
}

.draggable-item {
    display: inline-block;
    margin: 0 8px 8px 0;
    font-size: 0;
    line-height: 0;
    vertical-align: middle;
    position: relative;
}

.upload-img {
    display: inline-block;
    margin: 0 8px 8px 0;
    font-size: 0;
    line-height: 0;
    overflow: hidden;
    vertical-align: middle;
}

.icon-close {
    position: absolute;
    right: 0;
    top: 0;
    font-size: 18px;
    color: #00be8b;
    z-index: 1;
}
</style>
